<?php
/**
 * Created by PhpStorm.
 * User: 李晓辉
 * Date: 2019/6/19
 * Time: 16:08
 */

namespace app\home\controller;
use app\home\model\Attendance;
use think\Request;
use think\Session;

class Attendances extends Base
{
   //获取用户的考勤信息
   public function atten(Request $request){
     $id = $request->post("id");
     $res = collection(Attendance::where(["userid"=>$id])->field("startDate,name")->select())->toArray();
     $atten = [
       "cd"=>0,
       "qq"=>0,
       "bj"=>0,
       "sj"=>0,
       "yqd"=>0,
     ];
     foreach($res as $val){
       if($val["name"]=="事假"){
         $atten['sj']++;
       }else if($val["name"]=="病假"){
         $atten['bj']++;
       }else if($val["name"]=="缺勤"){
         $atten['qq']++;
       }else if($val["name"]=="迟到"){
         $atten['cd']++;
       } else if($val["name"]=="已签到"){
         $atten['yqd']++;
       }
     }
     $arr = [
       "setting" => $this->getAllSetting(),
       "data"=>$res,
       "atten"=>$atten
     ];
     return json($arr);
   }

}

